package v2;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComponent;
import javax.swing.Timer;

@SuppressWarnings("serial")
public class ParticleSpawn extends JComponent{

	private double x;
	private double y;
	Timer myTimer;
	private TimerListener listener;
	private ParticleViewer myViewer;
	
	public ParticleSpawn(double x, double y, int t) {
		this.x = x;
		this.y = y;
		listener = new TimerListener();
		
		myTimer = new Timer(t,listener);
		myTimer.start();
	}
	
	private ParticleViewer getViewer(){
		if(myViewer==null){
			//this is 4 parents deep. weird.
			myViewer = (ParticleViewer) this.getParent().getParent().getParent().getParent();
		}
		return myViewer;
	}
	
	private class TimerListener implements ActionListener{
		public void actionPerformed(ActionEvent arg0) {
			getViewer().add(new Particle(x,y));
		}
	}
}
